﻿using MVCOA.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MVCOA.Areas.Manage.Controllers
{
    public class SearchKeyController : Controller
    {
        //
        // GET: /Manage/SearchKey/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult Getdata()
        {
            IBLL.ISearchKeyBLL first = OperateContext.Current.BLLSession.ISearchKeyBLL;
            List<MODEL.SearchKey> list = first.GetListBy(q => true).Select(s => s.ToPOCO()).ToList();
            var gridData = new
            {
                Rows = list,
                Total = 1
            };
            return Json(gridData);
        }
        [HttpPost]
        public void Setdata(FormCollection fc)
        {
            // IBLL.ICate_FisrtBLL first = OperateContext.Current.BLLSession.ICate_FisrtBLL;
            string names = fc["name"];
            int ids = Convert.ToInt32(fc["id"]);      
            if (ids == 0)
            {
                if (OperateContext.Current.BLLSession.ISearchKeyBLL.GetListBy(s => s.name == names).ToList().Count() == 0)
                {
               
                        MODEL.SearchKey s = new MODEL.SearchKey() { name = names};
                        OperateContext.Current.BLLSession.ISearchKeyBLL.Add(s);
                   
                }


            }
            else
            {

                    MODEL.SearchKey s = new MODEL.SearchKey() { id = ids, name = names};
                    OperateContext.Current.BLLSession.ISearchKeyBLL.Modify(s, "name");
             

            }
        }
        [HttpPost]
        public void Deldata(FormCollection fc)
        {
            int ids = Convert.ToInt32(fc["id"]);
            //OperateContext.Current.BLLSession.ICate_ThirdBLL.DelBy(s => s.firstId == ids);
            //OperateContext.Current.BLLSession.ICate_SecondBLL.DelBy(s => s.firstId == ids);
            OperateContext.Current.BLLSession.ISearchKeyBLL.DelBy(s => s.id == ids);
        }
    }
}
